package se.liu.oschi129.game.levels.level02;

import se.liu.johfa428.levelstate.LevelState;
import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.game.objects.*;
import se.liu.oschi129.game.objects.blocks.breakable.*;
import se.liu.oschi129.game.objects.blocks.solid.*;
import se.liu.oschi129.game.objects.enemies.*;
import se.liu.oschi129.game.objects.items.*;
import se.liu.oschi129.game.objects.platforms.*;
import se.liu.oschi129.level.levelspace.LevelInterface;
import se.liu.oschi129.world.model.*;

/**
 * This is a level.
 * 
 * @author oschi129
 */
public class Level02 implements LevelInterface {

	public void createWorld(World world, LevelState levelState) {
		
		// Set the startup settings for the world
		world.setWidth(2400);
		world.setHeight(222);
		world.setTime(180);
		
		// Set the physical rules
		world.setPhysicalRules(new WorldPhysicalRules());
		
		// Add a statusbar
		world.addObjectSynchronized(new ObjectStatusBar(world));
		
		// Add a background
		world.addObjectSynchronized(new ObjectBackground(world,true,false,AnimationSpace.get("img_background04"),0,0));
		
		// Add a player to the world
		ObjectPlayer player;

		player = new ObjectPlayer(16,222-48);
		player.setPhysicalRules(world.getPhysicalRules());
		world.addObjectSynchronized(player);
		world.addInteractiveObjectSynchronized(player);
		
		// Set the world view to follow the player
		world.setView(new WorldView(256,222,player));
		
		for (double x = 128; x < 320; x+= 16) {
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, x, 144));
			if (x != 160 && x != 240)
				world.addObjectSynchronized(new ObjectBreakableBlock10(true, x, 64));
		}
		for (double y = 80; y < 144; y+= 16) {
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, 128, y));
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, 304, y));
		}
		
		// Add a "secret" block with coins
		ObjectBlock container;
		
		container = new ObjectBlock10(true, 160, 64);
		for (double n = 0; n < 8; n++)
			container.addContent(new ObjectCoin(0,0));
		world.addObjectSynchronized(container);
		
		container = new ObjectBlock10(true, 240, 64);
		container.addContent(new ObjectPowerupMushroom(0,0));
		world.addObjectSynchronized(container);
		
		// Add some solids to the world
		for (double x = 0; x < 512; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock14(true, x, 206));
		}
		world.addObjectSynchronized(new ObjectBlock01(true, 512, 206));
		
		// Add a platform between the solids
		world.addObjectSynchronized(new ObjectStaticPlatform02(528, 160));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),544,176));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),544,192));
		
		world.addObjectSynchronized(new ObjectStaticPlatform02(608, 96));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),624,112));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),624,128));
		
		world.addObjectSynchronized(new ObjectStaticPlatform03(768, 160));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),800,176));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),800,192));
		
		// Add some solids to the world
		world.addObjectSynchronized(new ObjectBlock01(true, 608, 206));
		for (double x = 624; x < 1024; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock14(true, x, 206));
		}
		world.addObjectSynchronized(new ObjectBlock01(true, 1024, 206));
		
		// Add an enemy
		world.addObjectSynchronized(new ObjectEnemyToadCollider(608,160,16,46));
		world.addObjectSynchronized(new ObjectEnemyToadRunning(800,160));
		world.addObjectSynchronized(new ObjectEnemyToadCollider(1024,160,16,46));
		
		// Add an enemy on a platform
		world.addObjectSynchronized(new ObjectEnemyToadCollider(944, 0,16,64));
		world.addObjectSynchronized(new ObjectStaticPlatform03(960, 64));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),992,80));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),992, 96));
		world.addObjectSynchronized(new ObjectEnemyToadThrowing(980,0));
		world.addObjectSynchronized(new ObjectEnemyToadCollider(1024, 0,16,64));
		
		// Add a movable platform between the solids
		ObjectMovablePlatformCollider collider;
		collider = new ObjectMovablePlatformCollider(1024, 206, 16,16);
		collider.setHorizontalSpeed(2);
		world.addObjectSynchronized(collider);
		
		collider = new ObjectMovablePlatformCollider(1264, 206, 16,16);
		collider.setHorizontalSpeed(-2);
		world.addObjectSynchronized(collider);
		
		ObjectMovablePlatform platform;
		
		platform = new ObjectMovablePlatform(1040, 206, 49, 9);
		platform.setAnimation(AnimationSpace.get("img_platform01"));
		platform.setVisible(true);
		platform.setHorizontalSpeed(2);
		world.addObjectSynchronized(platform);
		
		// Add some solids to the world
		world.addObjectSynchronized(new ObjectBlock01(true, 1264, 206));
		for (double x = 1280; x < 1600; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock14(true, x, 206));
		}
		world.addObjectSynchronized(new ObjectBlock01(true, 1600, 206));
		
		// Add a platform inside some solids
		for (double y = 160; y < 190; y+= 16) {
			world.addObjectSynchronized(new ObjectBlock01(true, 1312, y));
			world.addObjectSynchronized(new ObjectBlock01(true, 1408, y));
		}
		for (double x = 1328; x < 1408; x+=16)
			world.addObjectSynchronized(new ObjectCoin(true,x,190));
		world.addObjectSynchronized(new ObjectStaticPlatform03(1328, 160));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),1360,176));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),1360,192));
		
		// Add a "secret" container
		container = new ObjectBlock04(false, 1424, 160);
		container.addContent(new ObjectPowerupSpike(0,0));
		world.addObjectSynchronized(container);
		
		// Adda a platform
		world.addObjectSynchronized(new ObjectStaticPlatform02(1504, 96));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),1520,112));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),1520,128));
		
		// Add some solids
		world.addObjectSynchronized(new ObjectBlock01(true, 1680, 206));
		for (double x = 1696; x < 2400; x+= 16) {
			world.addObjectSynchronized(new ObjectBlock14(true, x, 206));
		}
		
		// Add an enemy
		world.addObjectSynchronized(new ObjectEnemyToadCollider(1680,160,16,46));
		world.addObjectSynchronized(new ObjectEnemyToadRunning(2208,160));
		world.addObjectSynchronized(new ObjectEnemyToadCollider(2368,160,16,46));
		
		// Add a platform
		world.addObjectSynchronized(new ObjectStaticPlatform02(1856, 96));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),1872,112));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),1872,128));
		
		world.addObjectSynchronized(new ObjectStaticPlatform03(1968, 160));
		world.addObjectSynchronized(new ObjectBackground(world,false,false,AnimationSpace.get("img_platform_base01"),2000,176));
		world.addObjectSynchronized(new ObjectBackground(world,false,true,AnimationSpace.get("img_platform_base02"),2000,192));
		
		for (double x = 2240; x < 2320; x+= 16) {
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, x, 144));
			if (x != 160 && x != 240)
				world.addObjectSynchronized(new ObjectBreakableBlock10(true, x, 64));
		}
		for (double y = 80; y < 144; y+= 16) {
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, 2240, y));
			world.addObjectSynchronized(new ObjectBreakableBlock10(true, 2304, y));
		}
		// Add an enemy
		world.addObjectSynchronized(new ObjectEnemyToadThrowing(2260,128));
		
		world.addObjectSynchronized(new ObjectGoal(levelState, 2368,222-176-16));
		
	}
	
}
